import React, { useState } from 'react'
// 1. 在函数式组件中定义自己的内部状态

export default function HookState() {
    // useState  一般用于定义单个状态 
    //const [状态, 修改状态的方法] = useState(初始值)
    // const [count, setCount] = useState(888)
    const [obj, setObj] = useState({
        name: "张三",
        age: 18
    })

    return (
        <div>
            {/* HookState --- { count }
            <button onClick={() => {
                setCount(count+1)
            }}>+ 1 </button> */}

            <p>
                {obj.name}
            </p>
            <p>
                {obj.age}
            </p>

            <button onClick={() => {
                setObj({
                    ...obj,
                    name: "李四" 
                })
            }}>更改名字 </button>
        </div>
    )
}
